# _*_ coding:utf-8 _*_
# @Time : 2023/6/7 16:48
# @Author : wsl
# @File : demo
# @Project : python  模拟浏览器搜索
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

s = Service('chromedriver.exe')
driver = webdriver.Chrome(service=s)
driver.get('https://www.baidu.com')

time.sleep(2)

# 搜索周杰伦
input = driver.find_element(by=By.CSS_SELECTOR, value='#kw')
input.send_keys('周杰伦')
time.sleep(2)

button = driver.find_element(by=By.ID, value='su')
button.click()
time.sleep(2)

# 滑到最低
js_bottom = 'document.documentElement.scrollTop=100000'
driver.execute_script(js_bottom)
time.sleep(2)

# 获取下一页的按钮
next = driver.find_element(by=By.XPATH, value='//a[@class="n"]')
next.click()
time.sleep(2)

# 返回上一页
driver.back()
time.sleep(2)

driver.forward()
time.sleep(3)

driver.quit()
